<?php
class Ziying extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('ziying_model');
        $this->load->model('comment_model');
        $this->load->model('category_model');
    }

    public function getlist()
    {
    	$data=$_GET;
        $ziying = $this->ziying_model->getList($data);
        
        $this->success($ziying);
    }

    public function detail()
    {
        if(empty($_GET['id'])||!is_numeric($_GET['id']))
    	{$this->error('id is null');}
    	
        $id = $_GET['id'];
        $data = $this->ziying_model->detail($id);
        
        if(empty($data))
        {$this->error('自营项目不存在');}
        //评论
//         $con_data['type'] = 'ZIYING';
//         $con_data['id'] = $id;
//         $con_data['limit'] = 5;
//         $con_data['offset'] = 0;
//         $coms = $this->comment_model->getActivityOrTrackComments($con_data);
//         $data['coms'] = $coms;
        $this->success($data);

    }
    /**
     * 获取APP上自营项目行程介绍和价格介绍
     * */
    public function getDesc(){
    	if(empty($_GET['id'])||!is_numeric($_GET['id']))
    	{$this->error('id is null');}
    	 
    	$id = $_GET['id'];
    	$data = $this->ziying_model->getDesc($id);
    	$this->success($data);
    }
    
    public function getComments()
    {
    	//自营id
    	if(empty($_GET['id']))
    	{$this->error('id is null');}
    	$id = $_GET['id'];
    	//分页参数
    	if(empty($_GET['page']))
    		$page = 1;
    	else
    		$page = $_GET['page'];
    	 
    	$limit=$page*5;
    	$offset=0;
    	//评论
    	$con_data['type'] = "ZIYING";
    	$con_data['id'] = $id;
    	$con_data['limit'] = $limit;
    	$con_data['offset'] = $offset;
    	$coms = $this->comment_model->getActivityOrTrackComments($con_data);
    	$this->success($coms);
    }

    public function gettype()
    {
    	//获取自营(id=4)的分类
        $data =  $this->category_model->all_categories(array('parentId'=>4));
        $this->success($data);
    }
    
    /**
     * 获取案例展示首页信息
     * @return mixed
     * */
    public function zycaseIndex()
    {
    	$res = $this->ziying_model->caseCovers();
    	
    	if (!empty($res)) {
    		$this->success($res);
    	} else {
    		$this->error('数据加载失败');
    	}
    	
    } 

}